<?php

namespace app\common\service\qrcode;
use app\common\library\WsgtLog;
class Gifts extends Base{
    /* @var array $pages 小程序码链接 */
    private $pages = 'packageA/pages/lpMsg/lpMsg';
    /**
     *  获取小程序二维码
     */
    public function getImage($user_id="2_1",$show='show'){
        // 判断海报图文件存在则直接返回url
        $scene = "user_id:{$user_id},show:{$show}";
        $fileName = $user_id.'_' . md5($user_id . $scene . $this->pages) . '.png';
        $savePath=WEB_PATH."/image/".$user_id.'/'.$fileName;
        if (file_exists($savePath)) {
            $log = WsgtLog::instance();
            $log->setFilename('image/erweima');
            $log->info("https://www.globalbt.cn/image/".$user_id.'/'.$fileName, '传参信息');
            return "https://www.globalbt.cn/image/".$user_id.'/'.$fileName;
        }
        //下载小程序码
        $qrcode = $this->saveQrcode($user_id, $scene, $this->pages);
        return $qrcode;
    }
    /**
     * 海报图文件路径
     * @return string
     */
    private function getPosterPath(){
        //保存路径
        $tempPath = WEB_PATH.'temp' . '/1/';
        !is_dir($tempPath) && mkdir($tempPath, 0755, true);
        return $tempPath . $this->getPosterName();
    }
    /**
     * 海报图文件名称
     */
    private function getPosterName(){
        return 'erweima_' . md5('1_1') . '.png';
    }
}